package com.rem.elasticsearch.apidemo.index;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

import java.io.IOException;
import java.util.Arrays;

import static org.apache.http.HttpHost.DEFAULT_SCHEME_NAME;

/**
 * @author Rem
 * @date 2021-05-16
 */

@Slf4j
public class IndexSearch {


    public static void main(String[] args) throws IOException {
        // 创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, DEFAULT_SCHEME_NAME))
        );

        GetIndexResponse userRes = esClient.indices().get(new GetIndexRequest("user"), RequestOptions.DEFAULT);

        System.out.println(userRes.getAliases());
        //System.out.println(userRes.getDataStreams());

        System.out.println(userRes.getDefaultSettings());
        System.out.println(Arrays.toString(userRes.getIndices()));
        System.out.println(userRes.getMappings());
        System.out.println(userRes.getSettings());


        // 关闭ES客户端
        esClient.close();
    }
}
